<html>
<head>
<title>Movie Database</title>
</head>
<body>
<h1>Query the Movie Database</h1>
<h2>Prasanth Veerina & Samir Mody</h2>

<form action="query.php" method="get">
<textarea name="query" rows=5 cols=30> 
</textarea>

<input type="submit"/>
</form>

<?php
$query = $_GET["query"];
if ($query) {
	$db_connection = mysql_connect("localhost", "cs143", "");
	mysql_select_db("CS143", $db_connection);

	$rs = mysql_query($query, $db_connection);

	print "<table border=1> <tr>";

	$i = 0;
	while ($i < mysql_num_fields($rs)) {
		$meta = mysql_fetch_field($rs, $i);
		print "<td align=\"center\" > <strong>$meta->name</strong></td>";
		$i++;	
	}

	print "</tr>";



	while($row = mysql_fetch_row($rs)) {
		print "<tr>";
	    $j = 0;
		while ($j < mysql_num_fields($rs)) {
			$temp = $row[$j];
			if ($temp) {
				print "<td> $temp </td>";			
			} else{
				print "<td> N/A </td>";
			}
			
			$j++;
		}

		print "</tr>";
	}

	print "</table>";


	mysql_close($db_connection);
}
?>

</body>
</html>